{% extends 'layout/manage.html' %}
{% block css %}
    <style>
        .err-msg {
            color: red;
            font-size: 12px;
            position: absolute;
        }

        .star {
            margin-top: 10px;
        }
        .panel-body {
            padding: 0;
            display: flex;
            flex-direction: row;
            justify-content: left;
            align-items: flex-start;
            flex-wrap: wrap;
        }

        .panel-body > .item {
            border-radius: 6px;
            {#width: 228px;#}
            width: 226px;
            border: 1px solid #dddddd;
            margin: 20px 10px;

        }

        .panel-body > .item:hover {
            border: 1px solid #f0ad4e;
        }

        .panel-body > .item > .title {
            height: 104px;
            color: white;
            display: flex;
            justify-content: center;
            align-items: center;
            border-top-left-radius: 6px;
            border-top-right-radius: 6px;
            font-size: 15px;
            text-decoration: none;
        }

        .panel-body > .item > .info {
            padding: 10px 10px;

            display: flex;
            justify-content: space-between;

            border-bottom-left-radius: 6px;
            border-bottom-right-radius: 6px;
            color: #8c8c8c;

        }

        .panel-body > .item > .info a {
            text-decoration: none;
        }

        .panel-body > .item > .info .fa-star {
            font-size: 18px;
        }

        .color-radio label {
            margin-left:0 ;
            padding-left: 0;
        }
        .color-radio input[type='radio']{
            opacity: 0;
            display: none;
        }
        .color-radio input[type='radio'] + .cycle {
            display: inline-block;
            height: 25px;
            width: 25px;
            border-radius: 50%;
            border: 2px solid #dddddd;
        }
        .color-radio input[type='radio']:checked + .cycle{
            border: 2px solid black;
        }
    </style>
{% endblock %}
{% block content %}
    <div class="container-fluid project">
        <a class="btn btn-primary " data-toggle="modal" data-target="#myModal"><i class="fa fa-plus"
                                                                                  aria-hidden="true"></i>&nbsp;创建项目</a>

        {#  展示星标项目 #}
        <div class="panel panel-info star">
            <div class="panel-heading"><i class="fa fa-star" aria-hidden="true" style="color: #ff6700"></i>&nbsp;星标</div>
            <div class="panel-body">
                {% for item in project_dict.star %}
                     <div class="item">
                        <a href="{% url 'dashboard' project_id=item.value.id %}" class="title" style="background-color: {{ item.value.get_color_display }}"> {{ item.value.name }}</a>
                        <div class="info">
                            <div>
                                <a href="{% url 'project_unstar' project_type=item.type project_id=item.value.id %}">
                                    <i class="fa fa-star" aria-hidden="true" ></i>
                                    <span>{{ item.value.creator.username }}</span>
                                </a>
                            </div>
                            <div>
                                <i class="fa fa-user-o" aria-hidden="true"></i>
                                <span>{{ item.value.join_count }}</span>
                            </div>
                        </div>
                    </div>
                {% endfor %}
            </div>
        </div>

        {#  展示用户所创建的项目 #}
        <div class="panel panel-default star">
            <div class="panel-heading"><i class="fa fa-address-book-o" aria-hidden="true"></i>&nbsp;我创建的项目</div>
            <div class="panel-body">
                {% for item in project_dict.my %}
                     <div class="item">
                        <a href="{% url 'dashboard' project_id=item.id %}" class="title" style="background-color: {{ item.get_color_display }}"> {{ item.name }}</a>
                        <div class="info">
                            <div>
                                <a href="{% url 'project_star' project_type='my' project_id=item.id %}">
                                    <i class="fa fa-star" aria-hidden="true" style="color: #d5d5d5"></i>
                                    <span>{{ item.creator.username }}</span>
                                </a>
                            </div>
                            <div>
                                <i class="fa fa-user-o" aria-hidden="true"></i>
                                <span>{{ item.join_count }}</span>
                            </div>
                        </div>
                    </div>
                {% endfor %}
            </div>
        </div>

        {#  展示用户所参与的项目 #}
        <div class="panel panel-primary star">
            <div class="panel-heading"><i class="fa fa-sign-in" aria-hidden="true"></i>&nbsp;我参与的项目</div>
            <div class="panel-body">
                {% for item in project_dict.join %}
                    <div class="item">
                        <a href="{% url 'dashboard' project_id=item.id %}" class="title" style="background-color: {{ item.get_color_display }}"> {{ item.name }}</a>
                        <div class="info">
                            <div>
                                <a href="{% url 'project_star' project_type='join' project_id=item.id %}">
                                    <i class="fa fa-star" aria-hidden="true" style="color: #d5d5d5"></i>
                                    <span>{{ item.creator.username }}</span>
                                </a>
                            </div>
                            <div>
                                <i class="fa fa-user-o" aria-hidden="true"></i>
                                <span>{{ item.join_count }}</span>
                            </div>
                        </div>
                    </div>
                {% endfor %}
            </div>
        </div>
    </div>

    {#    模态框#}
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span>
                    </button>
                    <h4 class="modal-title" id="myModalLabel">新建项目</h4>
                </div>
                <div class="modal-body">
                    <form id="form-pro">
                        {% csrf_token %}
                        {% for field in form %}
                            <div class="form-group">
                                <label for="{{ field.id_for_label }}">{{ field.label }}</label>
                                {{ field }}
                                <span class="err-msg"></span>
                            </div>
                        {% endfor %}
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal" id="cancel">取消</button>
                    <button type="button" class="btn btn-primary" id="save">保存</button>
                </div>
            </div>
        </div>
    </div>
{% endblock %}

{% block js %}
    <script>
        // 点击保存 获取输入框的值 提交post 请求
        {#let regData =  // 获取form表单下所有的数据信息 + csrf token#}
            $('#save').click(function () {
                $.ajax({
                    url: '{% url 'project_list' %}',
                    type: 'post',
                    data: $('#form-pro').serialize(),
                    success: function (data) {
                        if (data.status) {
                            // 验证成功，刷新网页
                            location.href = location.href
                        } else {
                            // 显示错误信息
                            $.each(data.error, function (key, value) {
                                // key error 字典里的key 即字段名
                                $('#id_' + key).next().text(value[0])
                                setTimeout(function () {
                                    $('.err-msg').text('');
                                }, 1000)
                            })
                        }
                    }
                })
            })
    </script>
{% endblock %}